package com.jisu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jisu.dto.ModelDTO;
import com.jisu.mapper.ModelMapper;
import com.jisu.pojo.Model;
import com.jisu.service.ModelService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class ModelServiceImpl extends ServiceImpl<ModelMapper, Model> implements ModelService {
    @Override
    public List<Model> searchCarsByDTO(ModelDTO modelDTO) {
        return this.baseMapper.selectList(new LambdaQueryWrapper<Model>()
                .eq(modelDTO.getBrandId() != null, Model::getBrandId, modelDTO.getBrandId())
                .eq(modelDTO.getModelId() != null, Model::getModelId, modelDTO.getModelId())
                .like(StringUtils.hasText(modelDTO.getModelName()), Model::getModelName, modelDTO.getModelName())
                .eq(StringUtils.hasText(modelDTO.getModelTypeId()), Model::getModelTypeId, modelDTO.getModelTypeId()));
    }

}
